package com.estronger.shopmanage.ui.order.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.estronger.shopmanage.R;
import com.estronger.shopmanage.ui.order.bean.OrderAttributeBean;
import com.estronger.shopmanage.ui.order.bean.TaocanitemBean;
import com.estronger.shopmanage.utils.ConvertUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DingYG on 2017-07-28.
 */

public class TaoCan_Detail_ItemAdapter extends BaseAdapter {
    private List<OrderAttributeBean> mList = new ArrayList<>();
    Activity mContext;

    public TaoCan_Detail_ItemAdapter(Activity context, List<OrderAttributeBean> mList) {
        mContext = context;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if (mList != null)
            return mList.size();
        else
            return 0;
    }

    @Override
    public OrderAttributeBean getItem(int position) {
        // TODO Auto-generated method stub
        if (mList == null || mList.size() <= 0)
            return null;
        else
            return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final DetailItemView ltv;
        final OrderAttributeBean item = mList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.view_taocanshux_detail, null);
            ltv = new DetailItemView(convertView);
            convertView.setTag(ltv);
        } else {
            ltv = (DetailItemView) convertView.getTag();
        }
        try {
            if(mList.size()-1 == position){
                ltv.ivfGed.setVisibility(View.GONE);
            }else{
                ltv.ivfGed.setVisibility(View.VISIBLE);
            }
            ltv.tvfName.setText(item.getAttName()+":");
            ltv.tvfTcShux.setText(item.getAffiliatedName());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }
    public class DetailItemView {
        TextView tvfName;
        TextView tvfTcShux;
        ImageView ivfGed;

        public DetailItemView(View view) {
            this.tvfName = (TextView) view.findViewById(R.id.tvfShuxTitle);
            this.tvfTcShux = (TextView) view.findViewById(R.id.tvfShuxVuale);
            this.ivfGed = (ImageView) view.findViewById(R.id.ivfBottom);
        }
    }
}
